<?php

//包含公共文件
include '../../common/common.php';

//接收get传值,用于确定版块
// var_dump($_POST);
$detailBtn2 = $_POST['detailBtn2'];
$arrId2 = $_POST['arrId2'];
$strId2 = join(',' , $arrId2);
// var_dump($arrId2);
// var_dump($strId2);

//判断选项是否为空
if (!$arrId2) {

	exit('选项不得为空 <a href="'  . $_SERVER['HTTP_REFERER'] .'">返回上一页</a>');
}

//删除
if ($detailBtn2 == '删 除') {

	//物理删除数据库
	$delPost   = myDelete($link , DB_TABLE_DETAIL , " id  in  ($strId2)");
	$delReply = myDelete($link , DB_TABLE_DETAIL , " tid  in  ($strId2)");
	// var_dump($delPost);
	// var_dump($delReply);

	//判断是否为空
	if (!$delPost) {
		exit('删除失败 <a href="'  . $_SERVER['HTTP_REFERER'] .'">返回上一页</a>');
	}
	
	//跳转页面
	echo '删除成功';
	header('refresh:1;url=' . $_SERVER['HTTP_REFERER']);
}


//修改
if ($detailBtn2 == '恢 复') {

	//批量修改数据 (帖子)
	$resUpdate = myUpdate($link , DB_TABLE_DETAIL , ['isdel' => 0] , "id in ($strId2)");
	$resReply  = myUpdate($link , DB_TABLE_DETAIL , ['isdel' => 0 , 'detaildel' => 0] , " tid in ($strId2) ");
	// var_dump($resUpdate);
	// var_dump($resReply);

	//判断帖子是否修改成功 (无法判断评论,因为评论可能为空)
	if  (!$resUpdate) {
		exit('帖子恢复失败 <a href="'  . $_SERVER['HTTP_REFERER'] .'">返回上一页</a>');
	}

	//跳转页面
	echo '帖子恢复成功';
	header('refresh:1;url=' . $_SERVER['HTTP_REFERER']);
}
